// MCF_BPA.cpp: implementation of the CMCF_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/MCF_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMCF_BPA::CMCF_BPA()
{
	m_chType = 'M';
	m_chSubType = 'F';
	m_chChangeCode = ' ';

	m_dEMWS = 0;
	m_dPpu = 0;
	m_dQpu = 0;
	m_dMVABASE = 0;
	m_dRa = 0;
	m_dXdp = 0;
	m_dXqp = 0;
	m_dXd = 0;
	m_dXq = 0;
	m_dTdop = 0;
	m_dTqop = 0;
	m_dXl = 0;
	m_dSG10 = 0;
	m_dSG12 = 0;
	m_dD = 0;
	m_chType = 'M';
	m_chSubType = 'X';

	m_strCardType[0] = 'M';
	m_strCardType[1] = '*';
}

CMCF_BPA::CMCF_BPA(CMCF_BPA &mcfBPA):CUnit_BPA(mcfBPA)
{
	m_dEMWS = mcfBPA.m_dEMWS;
	m_dPpu = mcfBPA.m_dPpu;
	m_dQpu = mcfBPA.m_dQpu;
	m_dMVABASE = mcfBPA.m_dMVABASE;
	m_dRa = mcfBPA.m_dRa;
	m_dXdp = mcfBPA.m_dXdp;
	m_dXqp = mcfBPA.m_dXqp;
	m_dXd = mcfBPA.m_dXd;
	m_dXq = mcfBPA.m_dXq;
	m_dTdop = mcfBPA.m_dTdop;
	m_dTqop = mcfBPA.m_dTqop;
	m_dXl = mcfBPA.m_dXl;
	m_dSG10 = mcfBPA.m_dSG10;
	m_dSG12 = mcfBPA.m_dSG12;
	m_dD = mcfBPA.m_dD;
}

CMCF_BPA::~CMCF_BPA()
{

}

bool CMCF_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CMCF_BPA: FillEx): no basic information!\n");
		return false;
	}
	
	if (strlen(buffer)<17)
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}
	
	m_dEMWS = StrToDouble(&buffer[16],6);
	if(EndOfSec(&buffer[16],6))
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}

	m_dPpu = StrToDouble(&buffer[22],3,2,1.0);
	if(EndOfSec(&buffer[22],3))
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}

	m_dQpu = StrToDouble(&buffer[25],3,2,1.0);
	if(EndOfSec(&buffer[25],3))
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}

	m_dMVABASE = StrToDouble(&buffer[28],4,0,100);
	if(EndOfSec(&buffer[28],4))
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}

	m_dRa = StrToDouble(&buffer[32],4,4);
	if(EndOfSec(&buffer[32],4))
	{
		printf("Error in (CMCF_BPA: FillEx): mcf has no parameter!\n");
		return false;
	}

	m_dXdp = StrToDouble(&buffer[36],5,4);
	if(EndOfSec(&buffer[36],5))
		return true;

	m_dXqp = StrToDouble(&buffer[41],5,4);
	if(EndOfSec(&buffer[41],5))
		return true;

	m_dXd = StrToDouble(&buffer[46],5,4);
	if(EndOfSec(&buffer[46],5))
		return true;

	m_dXq = StrToDouble(&buffer[51],5,4);
	if(EndOfSec(&buffer[51],5))
		return true;

	m_dTdop = StrToDouble(&buffer[56],4,2);
	if(EndOfSec(&buffer[56],4))
		return true;

	m_dTqop = StrToDouble(&buffer[60],3,2);
	if(EndOfSec(&buffer[60],3))
		return true;

	m_dXl = StrToDouble(&buffer[63],5,4);
	if(EndOfSec(&buffer[63],5))
		return true;

	m_dSG10 = StrToDouble(&buffer[68],5,4);
	if(EndOfSec(&buffer[68],5))
		return true;

	m_dSG12 = StrToDouble(&buffer[73],4,3);
	if(EndOfSec(&buffer[73],4))
		return true;

	m_dD = StrToDouble(&buffer[77],3,2);

	return true;
}

bool CMCF_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CMCF_BPA: UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dEMWS,&buffer[16],6);
	DoubleToStr(m_dPpu,&buffer[22],3,2);
	DoubleToStr(m_dQpu,&buffer[25],3,2);
	DoubleToStr(m_dMVABASE,&buffer[28],4);
	DoubleToStr(m_dRa,&buffer[32],4,4);
	DoubleToStr(m_dXdp,&buffer[36],5,4);
	DoubleToStr(m_dXqp,&buffer[41],5,4);
	DoubleToStr(m_dXd,&buffer[46],5,4);
	DoubleToStr(m_dXq,&buffer[51],5,4);
	DoubleToStr(m_dTdop,&buffer[56],4,2);
	DoubleToStr(m_dTqop,&buffer[60],3,2);
	DoubleToStr(m_dXl,&buffer[63],5,4);
	DoubleToStr(m_dSG10,&buffer[68],5,4);
	DoubleToStr(m_dSG12,&buffer[73],4,3);
	DoubleToStr(m_dD,&buffer[77],3,2);
	
	return true;
}